lie = 1
while lie <= 9:
    hang = 1
    while hang <= lie:
        print('{} * {} = {:<4} '.format(hang, lie, hang * lie), end=' ')
        hang = hang + 1
    lie = lie + 1
    print('')


print('='*130)


lie = 9
while lie >= 1:
    hang = 1
    while hang <= lie:
        print('{} * {} = {:<4} '.format(lie, hang, hang * lie), end=' ')
        hang = hang + 1
    lie = lie - 1
    print('')


print('='*130)


'''
   上面两个是默认方法，下面的去掉IF判断的分支就是输出完整矩形乘法表
   通过IF判断的行数和列数的大小关系，选择输出算式
   较好理解
   两种形式的行数分别是从上往下1-9和从下往上1-9
'''





hang = 1
while hang <= 9:
    lie = 9
    while lie > 0:
        if lie <= hang:
            print('{} * {} = {:<4} '.format(lie, hang, hang * lie), end=' ')
        else:
            print('             ', end=' ')
            # 不用输出的算式使用同等长度的空格字符代替
        lie = lie - 1
    hang = hang + 1
    print('')
print('='*130)


hang = 9
while hang >= 1:
    lie = 9
    while lie > 0:
        if lie <= hang:
            print('{} * {} = {:<4} '.format(lie, hang, hang * lie), end=' ')
        else:
            print('             ', end=' ')
            # 不用输出的算式使用同等长度的空格字符代替
        lie = lie - 1
    hang = hang - 1
    print('')
print('='*130)

